package com.example.covid19.mapper;

import com.example.covid19.common.Dto.CkcDto;
import com.example.covid19.common.Dto.CrmDto2;
import com.example.covid19.common.Dto.Crmdto3;
import com.example.covid19.common.Dto.StuAddDto;
import com.example.covid19.entity.College;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.covid19.entity.SelectClass.CrmDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author BaiZhengChun
 * @since 2023-03-07
 */
public interface CollegeMapper extends BaseMapper<College> {
    @Select("SELECT " +
            " college.cname, " +
            " cravate.rname, " +
            " majeur.majeurname " +
            " FROM " +
            " college " +
            " INNER JOIN " +
            " cravate " +
            " ON " +
            " college.cid = cravate.cid " +
            " INNER JOIN " +
            " majeur " +
            " ON " +
            " cravate.xid = majeur.xid" +
            " WHERE " +
            " college.cid = cravate.cid")
    List<CrmDto> getCrm();
    @Select("SELECT " +
            "college.cname, " +
            "cravate.rname, " +
            "majeur.majeurname, " +
            "college.cid, " +
            "cravate.xid, " +
            "majeur.mid " +
            "FROM " +
            "college " +
            "INNER JOIN " +
            "cravate " +
            "ON " +
            "college.cid = cravate.cid " +
            "INNER JOIN " +
            "majeur " +
            "ON " +
            "cravate.xid = majeur.xid " +
            "WHERE " +
            "college.cid = cravate.cid"
    )
    List<Crmdto3> getCrm3();
    @Select("SELECT " +
            " college.cname, " +
            " cravate.rname, " +
            " college.cid, " +
            " cravate.xid " +
            "FROM " +
            " college " +
            " INNER JOIN " +
            " cravate " +
            " ON  " +
            "  college.cid = cravate.cid " +
            "WHERE " +
            " college.cid = cravate.cid ")
    List<CrmDto2> getCrm2();
    @Select("SELECT " +
            " classes.clname, " +
            " classes.ccid " +
            "FROM " +
            " classes " +
            " INNER JOIN " +
            " majeur " +
            " ON  " +
            "  classes.mid = majeur.mid " +
            " INNER JOIN " +
            " college " +
            " INNER JOIN " +
            " cravate " +
            " ON " +
            "  college.cid = cravate.cid AND " +
            "  majeur.xid = cravate.xid " +
            "WHERE " +
            " college.cname = '信息工程学院' AND " +
            " cravate.rname = '计算机科学与技术' AND" +
            " majeur.majeurname = '电子信息工程'")
    List<StuAddDto> getClasses();
    @Select("SELECT " +
            " college.cid,  " +
            " college.cname " +
            " FROM " +
            " college ")
    List<College> getCollege();
    /**
     * 检查是否有多余的数据，如有存在则禁止删除
     */
    @Select("SELECT " +
            " cravate.rname,  " +
            " majeur.majeurname, " +
            " classes.clname " +
            "FROM " +
            " college " +
            " LEFT JOIN " +
            " cravate " +
            " ON " +
            " college.cid = cravate.cid " +
            " LEFT JOIN " +
            " majeur " +
            " ON " +
            " cravate.xid = majeur.xid " +
            " LEFT JOIN " +
            " classes " +
            " ON " +
            " majeur.mid = classes.mid " +
            "WHERE " +
            " college.cid = #{id} ")
    List<CkcDto>candelete(@Param("id")Integer id);
}
